package com.vote.admin.controller;

import com.vote.admin.service.AdminUserService;
import com.vote.admin.service.AdminViewService;
import com.vote.admin.vo.param.SwitchParam;
import com.vote.admin.vo.result.UserResult;
import com.vote.admin.vo.result.ViewResult;
import com.vote.common.returns.RespEntity;
import com.vote.common.returns.RespTable;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin-user")
@Slf4j
@Api(value = "管理平台用户管理", tags = "管理平台用户管理")
public class AdminUserController {

    @Resource
    private AdminUserService adminUserService;

    @GetMapping("/list")
    @ApiOperation(value = "用户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "page", value = "当前页数", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "limit", value = "每页数量", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "column", value = "字段名", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "limit", value = "字段值", required = false)
    })
    public RespTable<List<UserResult>> userList(@RequestParam(value = "page", required = true) Integer page,
                                                @RequestParam(value = "limit", required = true) Integer limit,
                                                @RequestParam(value = "column", required = false) String column,
                                                @RequestParam(value = "value", required = false) String value) {
        RespTable<List<UserResult>> respTable = adminUserService.userList(page, limit, column, value);
        return respTable;
    }

    @PutMapping("/switch")
    @ApiOperation(value = "编辑用户类别")
    public RespEntity updateSwitch(SwitchParam switchParam) {
        RespEntity respEntity = adminUserService.updateSwitch(switchParam);
        return respEntity;
    }

}
